class_name HoldInfinityRandomTransferScroll
extends BaseHoldItem

var player_old_gravity: float = 0


func use():
	var player = holder as Player
	player.enable_input = false
	player_old_gravity = player.gravity
	player.gravity = 0
	player.velocity = Vector2.ZERO
	player.jump_start_height = 10000
	player.disable_hurt_collision()
	player.level.fisheye_transition.fisheye_in(fisheye_in_finish)
	
	AudioManager.play_sound("sfx_random_transfer")


func fisheye_in_finish():
	var player = holder as Player
	var new_position = player.level.pick_random_player_born_position()
	player.global_position = new_position
	await player.level.update_entity_active_process()
	await get_tree().create_timer(1.0).timeout
	player.level.fisheye_transition.fisheye_out(fisheye_out_finish)


func fisheye_out_finish():
	var player = holder as Player
	player.gravity = player_old_gravity
	player.enable_input = true
	player.enable_hurt_collision()
